﻿using IOP.Pulsar.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace IOP.Pulsar.ProductLineClients.TCP
{
    /// <summary>
    /// 字符串TCP客户端
    /// </summary>
    public class StringTCPClient : ProductLineTCPClient<StringContext>
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="services"></param>
        /// <param name="buildAction"></param>
        public StringTCPClient(IServiceProvider services, Action<IProductLineBuilder<StringContext>> buildAction)
            :base(services, buildAction) { }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="services"></param>
        /// <param name="buildAction"></param>
        public StringTCPClient(Action<IServiceCollection> services, Action<IProductLineBuilder<StringContext>> buildAction)
            :base(services, buildAction) { }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="buildAction"></param>
        public StringTCPClient(Action<IProductLineBuilder<StringContext>> buildAction)
        {
            IServiceCollection collections = new ServiceCollection();
            collections.AddLogging();
            _ServicesProvider = collections.BuildServiceProvider();
            _ProductLineBuilder = new ProductLineBuilder<StringContext>(_ServicesProvider);
            buildAction?.Invoke(_ProductLineBuilder);
            var productionLine = _ProductLineBuilder.Build();
            var entry = new DefaultProductLineEntry(productionLine);
            ProductLineEntry = entry;
        }
    }
}
